package world.criver.imagecompresstool.function;

import javafx.application.Platform;

import java.io.*;

public class funLock {

    /**
     * 检测是否存在该线程
     * @return
     */
    public boolean exist(){
        try {
            int n=0;
            Process p=new ProcessBuilder("cmd.exe","/c","tasklist | findstr \"ImageCompressTool.exe\"").start();
            try(BufferedReader re=new BufferedReader(new InputStreamReader(p.getInputStream(),"GBK"))){
                while(re.readLine()!=null)n++;
            }catch (Exception ee){
                throw new RuntimeException(ee);
            }
            p.destroy();
            return n>1;
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }

    /**
     * 将内容添加到剪切板
     * @param as
     */
    public void clip(String[] as) {
        new funCache().add(as);
    }
}
